package com.zmx.patients.adapter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.patients.R;
import com.zmx.patients.pojo.Meeting;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/8/9  2:01
 * 功 能：
 */

public class MeetingAdapter extends BaseAdapterRvList<MeetingAdapter.ViewHolder, Meeting> {

    private Handler handler;

    public MeetingAdapter(Activity activity, Handler handler) {
        super(activity);
        this.handler = handler;
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, Meeting meeting) {

        Glide.with(mActivity).load(meeting.getAvatar()).into(holder.doctor_head);
        holder.doctor_name.setText("主持医生："+meeting.getMaster_name());
        holder.title.setText(Html.fromHtml("<font color='#FF0000'>会议专题：</font>"+meeting.getTitle()));
        holder.number.setText("参与人数："+meeting.getNum()+"人");
        holder.state_time.setText("开始时间："+meeting.getAddtime());
        holder.end_time.setText("结束时间："+meeting.getEndtime());

        if (meeting.getStatus() == 0){
            holder.enter.setBackgroundResource(R.drawable.textview_false);
            holder.enter.setText("未开始");
        }else if (meeting.getStatus() == 1){
            holder.enter.setBackgroundResource(R.drawable.textview_true);
            holder.enter.setText("加入会议");
        }else{

            holder.enter.setBackgroundResource(R.drawable.text_b);
            holder.enter.setText("已结束");

        }

        holder.enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Message message = handler.obtainMessage();
                message.obj = meeting.getMeeting_id();
                message.what = 3;
                handler.sendMessage(message);

            }
        });

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        MeetingAdapter.ViewHolder holder = new MeetingAdapter.ViewHolder(inflater.inflate(R.layout.adapter_meeting, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.enter)
        TextView enter;
        @BindView(R.id.number)
        TextView number;
        @BindView(R.id.state_time)
        TextView state_time;
        @BindView(R.id.end_time)
        TextView end_time;
        @BindView(R.id.doctor_name)
        TextView doctor_name;
        @BindView(R.id.doctor_head)
        CircleImageView doctor_head;


        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }


}
